home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / Unknown / IconInfo.m < prev    next >
Encoding:
Text File  |  1991-01-25  |  2.2 KB  |  75 lines

  1. /* File: IconInfo.m - generates compile time files for Unknown application
  2.  *
  3.  * By: Christopher Lane
  4.  * Symbolic Systems Resources Group
  5.  * Knowledge Systems Laboratory
  6.  * Stanford University
  7.  *
  8.  * Date: 25 January 1991
  9.  *
  10.  * Copyright: 1989, 1990 & 1991 by The Leland Stanford Junior University.
  11.  * This program may be distributed without restriction for non-commercial use.
  12.  */
  13.  
  14. #import <stdio.h>
  15. #import <stdlib.h>
  16.  
  17. #import <objc/HashTable.h>
  18. #import <objc/typedstream.h>
  19.  
  20. #define DOCFILE "Makefile.docicons"
  21. #define ICONFILE "Unknown.iconheader"
  22. #define ARCHIVEFILE "Unknown.iconarchive"
  23. #define SECTIONFILE "Makefile.iconsections"
  24.  
  25. #define APP "app"
  26. #define STRING @encode(char *)
  27. #define BUFFERSIZE 512
  28.  
  29. void sys_error(char *string)
  30. {
  31.     perror(string);
  32.     exit(EXIT_FAILURE);
  33. }
  34.  
  35. void main(int argc, char *argv[])
  36. {
  37.     FILE *dfd, *ifd, *sfd;
  38.     NXTypedStream *afd;
  39.     int c;
  40.     BOOL first = YES;
  41.     HashTable *table = [HashTable newKeyDesc:STRING valueDesc:STRING];
  42.     char extension[BUFFERSIZE], application[BUFFERSIZE], program[BUFFERSIZE];
  43.     
  44.     if ((dfd = fopen(DOCFILE, "w")) == NULL) sys_error("fopen");
  45.     if ((ifd = fopen(ICONFILE, "w")) == NULL) sys_error("fopen");
  46.     if ((sfd = fopen(SECTIONFILE, "w")) == NULL) sys_error("fopen");
  47.     if ((afd = NXOpenTypedStreamForFile(ARCHIVEFILE, NX_WRITEONLY)) == NULL) exit(EXIT_FAILURE);
  48.     
  49.     (void) fprintf(dfd, "DOCICONS =");
  50.     (void) fprintf(sfd, "ICONSECTIONS =");
  51.        
  52.     while((c = scanf(" %[^:]:%[^:]:%[^\n]", &extension, &application, &program)) != EOF) {
  53.         if (c < 2) {
  54.             fprintf(stderr, "Invalid iconinfo entry (%s)!\n", extension);
  55.             exit(EXIT_FAILURE);
  56.             } 
  57.         if (c > 2) [table insertKey:NXUniqueString(extension) value:(void *)NXUniqueString(program)];
  58.         if (! first) (void) fprintf(dfd, " \\\n $(TIFFILEDIR)/%s.tiff", extension);
  59.         (void) fprintf(ifd, "%s\t%s\t%s\t%s\n", (first ? "F" : "S"), extension, application, (first ? APP : extension));
  60.         (void) fprintf(sfd, " \\\n -sectcreate __ICON %s $(TIFFILEDIR)/%s.tiff", (first ? APP : extension), extension);
  61.         first = NO;
  62.         }
  63.     
  64.     (void) fprintf(dfd, "\n");
  65.     (void) fprintf(sfd, "\n");
  66.     NXWriteObject(afd, table);
  67.     
  68.     (void) fclose(dfd);
  69.     (void) fclose(ifd);
  70.     (void) fclose(sfd);
  71.     NXCloseTypedStream(afd);
  72.     
  73.     exit(EXIT_SUCCESS);
  74. }
  75.